package org.wenhuayuan.uilibrary.refresh;


import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.wenhuayuan.uilibrary.R;

public class HiTextOverView extends HiOverView {
    private TextView text;
    private ImageView img;
    public HiTextOverView(@NonNull Context context) {
        super(context);
    }

    public HiTextOverView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.hi_refresh_overview, this, true);
        text = findViewById(R.id.text);
        img = findViewById(R.id.iv_rotate);

    }

    @Override
    public void onScroll(int scrollY, int pullRefreshHeight) {

    }

    @Override
    public void onVisible() {
        text.setText("下拉刷新");
        text.setTextColor(0xFF444444);
    }

    @Override
    public void onOverPull() {
        text.setText("松开刷新");
        text.setTextColor(0xFF222222);
    }

    Animation animation;
    @Override
    public void onRefresh() {
        text.setText("正在刷新...");
        text.setTextColor(0xFF000000);
        animation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate_anim);
        LinearInterpolator li = new LinearInterpolator();
        animation.setInterpolator(li);
        img.setAnimation(animation);
    }

    @Override
    public void onFinish() {
        img.clearAnimation();
    }
}
